
find_program(GO_EXECUTABLE
    NAMES go
    DOC "Go executable"
)

message("!!!!!!! ${GO_EXECUTABLE}")

if (NOT GO_EXECUTABLE)
    message(FATAL_ERROR "Go executable not found")
else()
    message("Building Go code")
    execute_process(
        COMMAND echo "Generating Go code"
        # COMMAND ${GO_EXECUTABLE} generate
        COMMAND_ECHO STDOUT
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        RESULT_VARIABLE GO_GENERATE_RESULT
    )
    if (NOT GO_GENERATE_RESULT EQUAL 0)
        message(FATAL_ERROR "Failed to generate Go code")
    endif()

    add_custom_target(hello_go ALL
        COMMENT "Building Go plugin"
        COMMAND 
            ${GO_EXECUTABLE} generate 
        
        USES_TERMINAL
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    )
endif()
